//
//  MCars.m
//  IOS-6day-1
//
//  Created by RIOS on 2018/4/14.
//  Copyright © 2018年 RIOS. All rights reserved.
//

#import "MCars.h"



@implementation MCars

- (instancetype)initWithDict:(NSDictionary *)dict{
    if (self = [super init]) {
//        self.cars = dict[@"cars"];
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
}

+ (instancetype)buildWithDict:(NSDictionary *)dict{
    return [[self alloc] initWithDict:dict];
}


+ (NSArray *)buildArray{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"car.plist" ofType:nil];
    NSArray *array = [NSArray arrayWithContentsOfFile:path];
    
    NSMutableArray *marray = [[NSMutableArray alloc] init];
    
    for (NSDictionary *dict in array) {
        MCars *cars = [self buildWithDict:dict];
        [marray addObject:cars];
        NSLog(@"%@",cars);
       
    }
  
    
    return marray;
    
}

-(NSString*)description{
//    NSString *dict = nil;
//    [self.cars enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
//        dict = [NSString stringWithFormat:@"\t%@ = %@;\n", key, obj];
//    }];
//    [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
//        [strM appendFormat:@"\t%@ = %@;\n", key, obj];
//    }];
    NSMutableString *name = [NSMutableString new];
    [self.carNames enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        [name appendFormat:@"%@,",obj ];
    }];
   [name appendFormat:@"length:%lu",(unsigned long)name.length];
    return [NSString stringWithFormat:@"%@: \n{\nuserId: %@ ,\nname: %@ ,\ncars: %@\n}",[self class],self.title,self.describe,name];
}
//
//-(NSString*)utf8Str:(NSString *)str{
//    NSString *unicodeStr = [NSString stringWithCString:[str UTF8String] encoding:NSUTF8StringEncoding];
//    return unicodeStr;
//    
//}


@end
